package tool

import (
	"regexp"
)

var regNonCN = regexp.MustCompile("^[\u4e00-\u9fa5]$")
var regNonNumAndEN = regexp.MustCompile("^[a-zA-Z0-9. ]*$")

// StrFilterForSpecChar filter the string all to chinese string
// NOTE: roman number is alse filtered
func StrFilterForSpecChar(rawStr string) string {
	temp := ""

	for _, c := range rawStr {
		if regNonCN.MatchString(string(c)) || regNonNumAndEN.MatchString(string(c)) {
			temp += string(c)
		}
	}

	return temp
}

// StrFilterToEn 过滤
// 该方法过滤字符串只有英文和数字
func StrFilterToEn(rawStr string) string {
	temp := ""

	for _, c := range rawStr {
		if regNonNumAndEN.MatchString(string(c)) {
			temp += string(c)
		}
	}

	return temp
}
